package com.ht.controller;

import com.ht.data.Result;
import com.ht.domain.bo.HospitalBO;
import com.ht.domain.po.TbHospital;
import com.ht.dto.TbHospitalDTO;
import com.ht.service.HospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("hospital")
@Api
@RefreshScope //开启自动刷新配置
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    /**
     * 添加医院信息
     * @param hospitalDTO 医院实体
     * @return
     */
    @ApiOperation("添加医院信息")
    @ApiImplicitParam(name = "hospitalDTO",value = "医院实体",required = true,paramType = "body",dataTypeClass = TbHospitalDTO.class)
    @PostMapping
    public Result addHospital(@RequestBody TbHospitalDTO hospitalDTO){
        HospitalBO hospitalBO = new HospitalBO();
        BeanUtils.copyProperties(hospitalDTO,hospitalBO);
        int i = hospitalService.addHospital(hospitalBO);
        if (i <= 0){
            return Result.ERROR();
        }
        return Result.OK();
    }

    /**
     * 根据医院id修改医院审核状态
     * @param hospitalId 医院id
     * @param hospitalStatus 审核状态
     * @return
     */
    @ApiOperation("根据医院id修改医院审核状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hospitalId",value = "医院id",required = true,paramType = "path",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "hospitalStatus",value = "医院审核状态1通过,2:不通过",required = true,paramType = "query",dataTypeClass = Integer.class)
    })
    @PutMapping("/{hospitalId}")
    public Result updateHospitalStatusByHospitalId(@PathVariable("hospitalId")Long hospitalId,@RequestParam("hospitalStatus")Integer hospitalStatus){
        int i = hospitalService.updateHospitalStatusByHospitalId(hospitalId,hospitalStatus);
        if (i <= 0){
            return Result.ERROR();
        }
        return Result.OK();
    }

}
